package sg.techstudio.suntec.dao;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import sg.techstudio.suntec.object.AdsObj;

@Repository("adsDao")
@Transactional
public class AdsDao {
	private static final Log log = LogFactory.getLog(AdsDao.class);
	
	@Autowired
	private SessionFactory sessionFactory;
	
	public AdsObj getAds(long id) {
		log.debug("getAds() entry");
		Session ses = sessionFactory.getCurrentSession();
		return (AdsObj) ses.get(AdsObj.class, id);
	}
	
	public void saveAds(AdsObj ads) {
		log.debug("saveAds() entry");
		Session ses = sessionFactory.getCurrentSession();
		ads.setUpdatedDate(new Date());
		ses.saveOrUpdate(ads);
	}
}
